<!--日志管理-->
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>日志管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="输入查询条件 ：">
        <el-input size="small" v-model="formInline.hostname" placeholder="主机名"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input size="small" v-model="formInline.ip" placeholder="IP"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input size="small" v-model="formInline.businessId" placeholder="业务ID"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input size="small" v-model="formInline.invocationIdStr" placeholder="调用链路ID"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">查询</el-button>
        <el-button size="small" type="primary" icon="el-icon-plus" @click="installLogServer">接入日志中心</el-button>
      </el-form-item>
    </el-form>

    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
              element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="index" width="100">
      </el-table-column>
      <el-table-column sortable prop="id" label="索引 ID" width="400">
      </el-table-column>
      <el-table-column sortable prop="log" label="日志信息" width="1778">
      </el-table-column>

    </el-table>

    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>

    <!-- 接入日志服务界面 -->
    <el-dialog :title="title" :visible.sync="installServerFormVisible" width="30%" @click="closeDialog">
      <el-form label-width="120px" :model="installServerForm" ref="serverForm">
        <el-form-item label="服务名称" prop="serverName">
          <el-input size="small" v-model="installServerForm.serverName" auto-complete="off" placeholder="输入微服务名称"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('serverForm')">保存
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {deptList, deptDetail,deptSave} from '../../api/userMG'
import Pagination from '../../components/Pagination'

export default {
  data() {
    return {
      loading: false, //是显示加载
      installServerFormVisible: false, //控制接入服务页面显示与隐藏
      title: '接入日志中心',
      installServerForm: {
        serverName: ''
      },

      detailFormVisible: false, //控制详情页面显示与隐藏
      detailForm: {
        logContent: ''
      },

      formInline: {
        page: 1,
        limit: 10
      },
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },
      //  详情参数
      detailParam: {
        id: ''
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取列表
    getdata(parameter) {
      this.loading = true
      /**
       * 调用接口，注释上面模拟数据 取消下面注释
       * 查询es
       */
      deptList(parameter)
        .then(res => {
          this.loading = false
          if (res.success == false) {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.listData = res.searchResultList
            // 分页赋值
            this.pageparm.currentPage = this.formInline.page
            this.pageparm.pageSize = this.formInline.limit
            this.pageparm.total = res.count
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //  接入日志服务
    installLogServer() {
      this.installServerFormVisible = true
    },
    // 接入日志中心提交表单
    submitForm(editData) {
      this.$refs[editData].validate(valid => {
        if (valid) {
          deptSave(this.installServerForm)
            .then(res => {
              this.installServerFormVisible = false
              this.loading = false
              if (res) {
                this.getdata(this.formInline)
                this.$message({
                  type: 'success',
                  message: '保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: '保存失败！'
                })
              }
            })
            .catch(err => {
              this.installServerFormVisible = false
              this.loading = false
              this.$message.error('保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },
    // 关闭弹出框
    closeDialog() {
      this.installServerFormVisible = false
      this.detailFormVisible = false
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
</style>


